package com.xiaobai.conf;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@EnableSwagger2
@Configuration
public class SwaggerConf {

    @Bean
    public Docket docket(Environment environment) {

        //设置swagger开关
        Profiles profiles = Profiles.of("dev", "test");
        boolean swaggerEnable = environment.acceptsProfiles(profiles);

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("group1")
                .enable(swaggerEnable)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.xiaobai"))
                .build();
    }

    /**
     * 配置swagge页面信息
     * @return
     */
    private ApiInfo apiInfo() {
        Contact contact = new Contact("王天文", "https://blog.csdn.net/qq_39464523", "wangtianwenn@163.com");
        return new ApiInfo("Swagger接口测试", "Swagger接口测试", "1.0",
                "", contact, "Apach 2.0 许可", "许可链接", new ArrayList<>());
    }

    @Bean
    public Docket docket1() {
        return new Docket(DocumentationType.SWAGGER_2).groupName("group2").enable(true);
    }
}
